package com.fisherman.config;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @User: fisherman
 * @Date: 2020/5/18 11:26
 */
public class MyTypeFilter implements TypeFilter {

    /**
     * @param metadataReader  读取到的当前正在扫描的类信息
     * @param metadataReaderFactory   可以获取到其他任何信息
     * @return
     */
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
            throws IOException {
        //获取当前注解的信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        //获取当前正在扫描的类的信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //获取当前类的资源信息
        Resource resource = metadataReader.getResource();
        //获取类名
        String className = classMetadata.getClassName();
        System.out.println("类名"+className);
        //指定一个规则   名字里面带有er的都打印出来
        if (className.contains("er")){
            return true;
        }
        return false;
    }
}
